]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
events: Re-use event messages where possible
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 9 Jun 2018 11:23:35 +0000 (13:23 +0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Fri, 13 Jul 2018 20:13:30 +0000 (20:13 +0000)
Destroying and recreating the entire events list on every change is not only
wasteful, it also breaks the clear functionality as messages scheduled for
removal are replaced with "new" messages after the first message has been
removed.

Address both issues by keeping track of all messages and re-use them
whenever possible.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/325

js/ui/calendar.js

index a46017ad05c80ef5240f773a8d0c720349a34914..651aac610a9918d92dadf98ed671e2d566bc96d5 100644 (file)
@@ -821,6 +821,8 @@ var EventsSection = new Lang.Class({
         this._desktopSettings.connect('changed', this._reloadEvents.bind(this));
         this._eventSource = new EmptyEventSource();
 
+        this._messageById = new Map();
+
         this.parent();
 
         this._title = new St.Button({ style_class: 'events-section-title',
@@ -875,20 +877,32 @@ var EventsSection = new Lang.Class({
 
         this._reloading = true;
 
-        this._list.destroy_all_children();
-
         let periodBegin = _getBeginningOfDay(this._date);
         let periodEnd = _getEndOfDay(this._date);
         let events = this._eventSource.getEvents(periodBegin, periodEnd);
 
+        let ids = events.map(e => e.id);
+        this._messageById.forEach((message, id) => {
+            if (ids.includes(id))
+                return;
+            this._messageById.delete(id);
+            this.removeMessage(message);
+        });
+
         for (let i = 0; i < events.length; i++) {
             let event = events[i];
 
-            let message = new EventMessage(event, this._date);
-            message.connect('close', () => {
-                this._ignoreEvent(event);
-            });
-            this.addMessage(message, false);
+            let message = this._messageById.get(event.id);
+            if (!message) {
+                message = new EventMessage(event, this._date);
+                message.connect('close', () => {
+                    this._ignoreEvent(event);
+                });
+                this._messageById.set(event.id, message);
+                this.addMessage(message, false);
+            } else {
+                this.moveMessage(message, i, false);
+            }
         }
 
         this._reloading = false;